<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>可写计算属性</title>
</head>
<body>
    <!-- 
        参考学习： https://cn.vuejs.org/guide/essentials/computed.html
    -->
    <script src="./vue.global.prod.js"></script>

    <div id="app">
        
        firstName : <input type="text" v-model="firstName" name="" id="">
        <br>
        lastName : <input type="text" v-model="lastName" name="" id="">
        <br>
        fullName : <input type="text" v-model="fullName" name="" id="">
    </div>

    <script>
        // 对象解构，从Vue对象中获取createApp函数
        const { createApp,ref,computed } = Vue

        // 通过createApp函数创建一个app对象
        const app = createApp({
            setup() {
                const firstName = ref('新')
                const lastName = ref('唐')

                const fullName = computed({
                    // getter
                    get() {
                        return firstName.value + ' ' + lastName.value
                    },
                    // setter
                    set(newValue) {
                        // 注意：我们这里使用的是解构赋值语法
                        [firstName.value, lastName.value] = newValue.split(' ')
                    }
                })

                return {
                    firstName,
                    lastName,
                    fullName
                }
                    
            }
            
        })

        // app对象挂载到id="app"的HTML元素，关联起来
        app.mount('#app')

    </script>

</body>
</html>